package com.hu.network.http.request.method;

import java.util.Map;

import com.hu.network.http.request.method.base.BaseHttpMethod;
import okhttp3.Request;

/**
 * 说明：
 *
 * @author ： hucanhua
 * @date ： 2017/10/26
 */
public class GetMethod extends BaseHttpMethod {
    private final Map<String, Object> params;

    public GetMethod(String tag, String url, Map<String, Object> params) {
        super(tag, url);
        this.params = params;
    }

    @Override
    protected Request buildRequest() {
        StringBuilder stringBuilder = new StringBuilder(url);
        if (params != null && params.size() > 0) {
            stringBuilder.append("?");
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                stringBuilder.append(entry.getKey()).append("=").append(entry.getValue());
            }
        }
        return new Request.Builder()
                .tag(tag)
                .url(stringBuilder.toString())
                .get()
                .build();
    }
}
